package com.api.util;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * CreateDate:2017年10月10日上午11:12:20 
 * @Description: 模拟缓存暂时存取数据  
 * @author:zw
 * @version V1.0
 */
public class ArrayUtil {
	
	private static Map<Object,Object> map;
	private static Object locker = new Object();
	public static Map<Object, Object> getOrAddCache(Object key) {
		if (map == null) {
			synchronized (locker) {
				map=new HashMap<>();
				map.put(key, null);
			}
		}
		return map;
	}

	public static void put(Object key, Object value) {
		getOrAddCache(key).put(key, value);
	}

	@SuppressWarnings("unchecked")
	public static <T> T get(Object key) {
		Object element = getOrAddCache(key).get(key);
		return element != null ? (T) element : null;
	}

	public static void remove( Object key) {
		getOrAddCache(key).clear();
	}

}
